package com.heiyanqiang.dao;

import com.heiyanqiang.domain.Member;
import com.heiyanqiang.domain.Orders;
import com.heiyanqiang.domain.Product;
import com.heiyanqiang.domain.Traveller;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrdersDao {

    /*
    *
    *
    *     private Integer id;
    private String orderNum;
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
    private Date orderTime;
    private String orderTimeStr;
    private int orderStatus;
    private int peopleCount;
    private List<Traveller> travellers;
    private Integer payType;
    private String payTypeStr;
    private String orderDesc;
    */

    @Select("select * from orders where id=#{ordersId}")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "orderNum",column = "orderNum"),
            @Result(property = "orderTime",column = "orderTime"),
            @Result(property = "peopleCount",column = "peopleCount"),
            @Result(property = "orderStatus",column = "orderStatus"),
            @Result(property = "payType",column = "payType"),
            @Result(property = "orderNum",column = "orderNum"),
            @Result(property = "orderDesc",column = "orderDesc"),
            @Result(property = "product",column = "productId",javaType = Product.class,one = @One(select = "com.heiyanqiang.dao.ProductDao.fidById")),
            @Result(property = "member",column = "memberId",javaType = Member.class,one = @One(select = "com.heiyanqiang.dao.MemberDao.findById")),
            @Result(property = "travellers",column = "id",javaType = java.util.List.class,many = @Many(select = "com.heiyanqiang.dao.TravellersDao.findById")),
    })
    Orders findById(Integer ordersId)throws Exception;



    @Select("select * from orders")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "orderNum",column = "orderNum"),
            @Result(property = "orderTime",column = "orderTime"),
            @Result(property = "peopleCount",column = "peopleCount"),
            @Result(property = "orderStatus",column = "orderStatus"),
            @Result(property = "payType",column = "payType"),
            @Result(property = "orderNum",column = "orderNum"),
            @Result(property = "orderDesc",column = "orderDesc"),
            @Result(property = "product",column = "productId",javaType = Product.class,one = @One(select = "com.heiyanqiang.dao.ProductDao.fidById")),
    })
    List<Orders> findAll() throws Exception;

}
